Element.prototype.dragNclick = (function (menu, elemClick) {

    var bTime = 0, //记录鼠标按下的时间戳
        eTime = 0, //记录鼠标抬起的时间戳
        oPos = [], //a标签（鼠标拖拽方块）的坐标
        wWidth = getViewPortSize().width, // 浏览器窗口的宽度
        wHeight = getViewPortSize().height,
        elemWidth = parseInt(getStyles(this, 'width')), //a标签的宽度
        elemHeight = parseInt(getStyles(this, 'height'));

    function drag() {
        var x,
            y,
            _self = this;
        //鼠标按下事件
        addEvent(this, 'mousedown', function (e) {
            var e = e || window.event;
            bTime = new Date().getTime(); //记录鼠标按下的时间戳
            oPos = [getStyles(_self, 'left'), getStyles(_self, 'top')]; //a标签（鼠标拖拽方块）的坐标
            menu.style.display = 'none';
            x = pagePos(e).X - parseInt(getStyles(_self, 'left'));
            y = pagePos(e).Y - parseInt(getStyles(_self, 'top'));
            addEvent(document, 'mousemove', mouseMove);
            addEvent(document, 'mouseup', mouseUp);
            // 取消冒泡
            cancelBubble(e);
            // 阻止默认事件
            preventDefaultEvent(e);
        });

        addEvent(document, 'contextmenu', function (e) {
            var e = e || window.event;
            preventDefaultEvent(e);
        });

        addEvent(document, 'click', function (e) {
            menu.style.display = 'none';
        });

        addEvent(menu, 'click', function (e) {
            var e = e || window.event;
            cancelBubble(e);
        });

        function mouseMove(e) {
            var e = e || window.event,
                elemLeft = pagePos(e).X - x,
                elemTop = pagePos(e).Y - y;
            // 这里做边界判断
            if (elemLeft <= 0) {
                elemLeft = 0;
            } else if (elemLeft >= wWidth - elemWidth) {
                elemLeft = wWidth - elemWidth - 1;
            }

            if (elemTop <= 0) {
                elemTop = 0;
            } else if (elemTop >= wHeight - elemHeight) {
                elemTop = wHeight - elemHeight - 1;
            }

            _self.style.left = elemLeft + 'px';
            _self.style.top = elemTop + 'px';
        }

        function mouseUp(e) {
            var e = e || window.event;
            eTime = new Date().getTime();

            // 通过时间戳来做模拟点击事件
            if (eTime - bTime < 100) {
                // 如果是点击事件 在快速拖拽的过程中要还原原来的位置
                _self.style.left = oPos[0] + 'px';
                _self.style.top = oPos[1] + 'px';
                elemClick();
            }
            removeEvent(document, 'mousemove', mouseMove);
            removeEvent(document, 'mouseup', mouseUp);
        }
    }
    drag.call(this); // 改变this指向为oLink --> a标签
});